package com.example.jeong.yuejian10.Adapter;



import android.content.Context;
import android.content.Intent;

import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.jeong.yuejian10.Activity.ClubDetailActivity;
import com.example.jeong.yuejian10.Bean.ClubBean;
import com.example.jeong.yuejian10.R;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.jeong.yuejian10.constant.Constant.CLUB_PHOTO_URL;


public class ClubListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContex;
    private List mDataList;
    private LayoutInflater mLayoutInflater;

    public ClubListAdapter(Context mContext, List mDataList) {
        this.mContex =  mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).
                inflate(R.layout.cardview_club, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final ClubBean entity = (ClubBean) mDataList.get(position);
        if (null == entity)
            return;
        ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.c_name.setText(entity.getC_name());
        System.out.print("c_name");
        String c_pic = CLUB_PHOTO_URL+entity.getC_pic();
        System.out.print("c_pic");
        if (!c_pic.equals("")) {
            Picasso.with(mContex).load(c_pic).into(viewHolder.c_pic);
        }

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle=new Bundle();
                bundle.putInt("c_id",entity.getC_id());
                bundle.putString("c_name",entity.getC_name());
                bundle.putString("c_pic",entity.getC_pic());
                bundle.putString("c_address",entity.getC_address());
                bundle.putString("c_time",entity.getC_time());
                bundle.putString("c_info",entity.getC_info());
                bundle.putString("c_phone",entity.getC_phone());
                Intent intent=new Intent(mContex,ClubDetailActivity.class);
                intent.putExtras(bundle);
                mContex.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView c_pic;
        TextView c_name;

        public ViewHolder(View itemView) {
            super(itemView);
            c_name = (TextView) itemView.findViewById(R.id.c_name);
            c_pic = (ImageView) itemView.findViewById(R.id.c_pic);

        }
    }
}
